package com.houweishi.module.evection.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.evection.domain.OaEvection;
import com.houweishi.module.evection.domain.OaEvectionApproval;
import com.houweishi.module.evection.service.IOaEvectionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出差申请Controller
 * 
 * @author houweishi
 * @date 2023-02-21
 */
@RestController
@RequestMapping("/module/evection")
public class OaEvectionController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(OaEvectionController.class);
    @Autowired
    private IOaEvectionService oaEvectionService;

    /**
     * 查询出差申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:evection:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaEvection oaEvection)
    {
        startPage();
        List<OaEvectionApproval> list = oaEvectionService.selectOaEvectionApprovalList(oaEvection);
        return getDataTable(list);
    }

    /**
     * 导出出差申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:evection:export')")
    @Log(title = "出差申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaEvection oaEvection)
    {
        List<OaEvection> list = oaEvectionService.selectOaEvectionList(oaEvection);
        ExcelUtil<OaEvection> util = new ExcelUtil<OaEvection>(OaEvection.class);
        util.exportExcel(response, list, "出差申请数据");
    }

    /**
     * 获取出差申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:evection:query')")
    @GetMapping(value = "/{evectionId}")
    public AjaxResult getInfo(@PathVariable("evectionId") Long evectionId)
    {
        return success(oaEvectionService.selectOaEvectionByEvectionId(evectionId));
    }

    /**
     * 新增出差申请
     */
    @PreAuthorize("@ss.hasPermi('module:evection:add')")
    @Log(title = "出差申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaEvection oaEvection)
    {
        try {
            return oaEvectionService.insertOaEvection(oaEvection);
        } catch (Exception e) {
            LOGGER.error("新增出差申请失败",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改出差申请
     */
    @PreAuthorize("@ss.hasPermi('module:evection:edit')")
    @Log(title = "出差申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaEvection oaEvection)
    {
        return toAjax(oaEvectionService.updateOaEvection(oaEvection));
    }

    /**
     * 删除出差申请
     */
    @PreAuthorize("@ss.hasPermi('module:evection:remove')")
    @Log(title = "出差申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{evectionIds}")
    public AjaxResult remove(@PathVariable Long[] evectionIds)
    {
        return toAjax(oaEvectionService.deleteOaEvectionByEvectionIds(evectionIds));
    }
}
